package org;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

import javax.persistence.Entity;
import vo.Custom;

public class DeleteAction extends ActionSupport {
	private String customname;
	private String password;
	Custom custom = new Custom();

	public String getCustomname() {
		return customname;
	}

	public void setCustomname(String customname) {
		this.customname = customname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String execute() throws Exception {

		if (getCustomname().length() >= 0 && getPassword().length() >= 0) {

			custom.setCustomname(customname);
			custom.setPassword(password);

			
			Session session = null;
		
				// ȡ��session����
				session = HibernateSessionFactory.getSession();
				Transaction tx = session.beginTransaction();
				List list =session.createCriteria(Custom.class)
						.add(Restrictions.eq("customname", customname)).list();
				if(list.size()>0){
					Custom custom = (Custom) list.get(0);
					session.delete(custom);
					tx.commit();
					return ("deletesuccess");
				}
				else{
					return ("deleteerror");
				}
			}
		  return "deleteerror";
		}
	}

			
					
				

			
		

	

